package com.acwing.partition11;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/1 16:11
 */
public class AC1096地牢大师 {

    private static final int N = 110;
    private static final int[][] dirs = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
    private static char[][][] g = new char[N][N][N];
    private static int[][][] dist = new int[N][N][N];
    private static Point[] q = new Point[N * N * N];
    private static int l, r, c;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String[] ss = reader.readLine().split(" ");
            l = Integer.parseInt(ss[0]);
            r = Integer.parseInt(ss[1]);
            c = Integer.parseInt(ss[2]);
            if (l == 0 && r == 0 && c == 0) break;
            Point start = null, end = null;
            for (int i = 1; i <= l; i++) {
                for (int j = 1; j <= r; j++) {
                    String s = reader.readLine();
                    for (int k = 1; k <= c; k++) {
                        dist[i][j][k] = 0;
                        g[i][j][k] = s.charAt(k - 1);
                        if (s.charAt(k - 1) == 'S') start = new Point(i, j, k);
                        else if (s.charAt(k - 1) == 'E') end = new Point(i, j, k);
                    }
                }
                reader.readLine();
            }
            int res = bfs(start, end);
            if (res == -1) writer.write("Trapped!\n");
            else writer.write(String.format("Escaped in %d minute(s).\n", res));
        }
        writer.flush();
    }

    private static int bfs(Point start, Point end) {
        int hh = 0, tt = 0;
        q[0] = start;
        while (hh <= tt) {
            Point cur = q[hh++];
            int x = cur.x, y = cur.y, z = cur.z;
            for (int[] dir : dirs) {
                int nx = x + dir[0], ny = y + dir[1], nz = z + dir[2];
                if (nx < 1 || ny < 1 || nz < 1 || nx > l || ny > r || nz > c || g[nx][ny][nz] == '#') continue;
                if (dist[nx][ny][nz] == 0 || dist[nx][ny][nz] > dist[x][y][z] + 1) {
                    dist[nx][ny][nz] = dist[x][y][z] + 1;
                    if (nx == end.x && ny == end.y && nz == end.z) return dist[nx][ny][nz];
                    q[++tt] = new Point(nx, ny, nz);
                }
            }
        }
        return -1;
    }

    private static class Point {
        private int x, y, z;

        public Point(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }
}
